# -*- coding:utf-8 -*-
# __auther__='jiangkai'

import selenium.webdriver
from selenium.webdriver.support.ui import Select
from time import sleep
from extScript.UploadPic import UploadPic
import os


class KY:
    def __init__(self):
        pass

    def test_ky(self, driver, dist=None):
        Select(driver.find_element_by_id("immovablesClass")).select_by_visible_text(u"矿业权")
        Select(driver.find_element_by_id("mine-type")).select_by_visible_text(dist["不动产类型2"])
        Select(driver.find_element_by_id("mine-proType")).select_by_visible_text(dist["不动产类型3"])

        driver.find_element_by_id("immovablesDetail").clear()
        driver.find_element_by_id("immovablesDetail").send_keys(dist["不动产具体描述"])
        Select(driver.find_element_by_id("immovablesGetWay")).select_by_visible_text(dist["不动产取得方式"])
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("immovablesDetail"))
        sleep(1)
        driver.find_element_by_id("immovablesLoc").clear()
        driver.find_element_by_id("immovablesLoc").send_keys(dist["不动产坐落"])
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("immovablesArea"))
        sleep(1)
        driver.find_element_by_id("immovablesArea").clear()
        driver.find_element_by_id("immovablesArea").send_keys(dist["面积"])

        if dist["证件类型"] == "不动产证号":
            driver.find_element_by_id("immovablesNo").clear()
            driver.find_element_by_id("immovablesNo").send_keys(dist["不动产证号"])
        else:
            driver.find_element_by_id("mineNo").clear()
            driver.find_element_by_id("mineNo").send_keys(dist["权证编号"])

        driver.find_element_by_id("rest-years1").clear()
        driver.find_element_by_id("rest-years1").send_keys(dist["剩余年限"])
        driver.find_element_by_id("valid-years").clear()
        driver.find_element_by_id("valid-years").send_keys(dist["有效期限"])
        driver.find_element_by_id("mineSpecies").clear()
        driver.find_element_by_id("mineSpecies").send_keys(dist["矿种"])
        driver.find_element_by_id("minestorage").clear()
        driver.find_element_by_id("minestorage").send_keys(dist["储量"])
        driver.find_element_by_id("infPCoordinate").clear()
        driver.find_element_by_id("infPCoordinate").send_keys(dist["拐点坐标"])
        driver.find_element_by_id("mineElevation").clear()
        driver.find_element_by_id("mineElevation").send_keys(dist["开采标高"])
        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("valid-years"))
        sleep(1)

        if dist["不动产类型2"] == "国有矿山":
            driver.find_element_by_id("copy13").click()
            driver.find_element_by_id("copy14").click()
            driver.find_element_by_id("copy15").click()
        elif dist["不动产类型2"] == "非国有矿山" and dist["不动产类型3"] == "采矿权":
            driver.find_element_by_id("copy14").click()
            driver.find_element_by_id("copy15").click()
        elif dist["不动产类型2"] == "非国有矿山" and dist["不动产类型3"] == "探矿权":
            driver.find_element_by_id("copy14").click()


        UploadPic(driver, "/html/body/content/div[1]/form/div/div[13]/div[12]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["地质矿产管理部门批复电子件或照片"]).upfile(
            "/html/body/content/div[1]/form/div/div[13]/div[12]/div[3]/div[1]/div[1]/div[2]/a")

        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("next-step2"))
        sleep(1)

        driver.find_element_by_name("interestedPartyView").click()
        UploadPic(driver, "/html/body/content/div[1]/form/div/div[18]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["利害关系人意见证明材料"]).upfile(
            "/html/body/content/div[1]/form/div/div[18]/div[3]/div[1]/div[1]/div[2]/a")

        driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id("next-step2"))
        sleep(1)

        driver.find_element_by_id("textarea2").clear()
        driver.find_element_by_id("textarea2").send_keys(dist["备注"])
        driver.find_element_by_id("next-step2").click()


if __name__ == '__main__':
    a = KY()
    a.test_ky()
